package com.web.java0328springboot.controller;

import com.web.java0328springboot.entity.Course;
import com.web.java0328springboot.entity.PageVO;
import com.web.java0328springboot.entity.ResponseResult;

import com.web.java0328springboot.entity.Student;
import com.web.java0328springboot.service.CourseService;
import com.web.java0328springboot.service.StudentService;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author lenovo
 * @Description
 * @Date2025/3/29 下午4:56
 */
@CrossOrigin
@RestController
@RequestMapping("/api/courses") // 添加统一前缀
public class CourseController {

//        @Resource
//    private CourseService courseService;
//    private StudentService studentService;
//    @RequestMapping(value = "/findCoursePage",method = RequestMethod.GET)
//    public ResponseResult findStudentPage(@RequestParam(name = "current",required = false,defaultValue = "1")int current,
//                                          @RequestParam(name = "pageSize",required = false,defaultValue = "10")int pageSize){
//        PageVO page = studentService.getStudentPage(current, pageSize);
//        return new ResponseResult(200,"OK",page);
//    }

//    @RequestMapping("/findCoursePage")
//    public ResponseResult findStudentPage(@RequestParam(name = "current",required = false,defaultValue = "1")int current,
//                                          @RequestParam(name = "pageSize",required = false,defaultValue = "10")int pageSize){
//        PageVO page = courseService.getCoursePage(current, pageSize);
//        return new ResponseResult(200,"OK",page);
//    }
//
//    @RequestMapping("addCourse")
//    public ResponseResult addCourse(Course course){
//        courseService.save(course);
//        return new ResponseResult(200,"OK",null);
//    }
//
//    @RequestMapping("updateCourse")
//    public ResponseResult updateCourse(Course course){
//        courseService.updateById(course);
//        return new ResponseResult(200,"OK",null);
//    }
//
//    @RequestMapping("deleteCourse")
//    public ResponseResult deleteCourse(Integer id) {
//        courseService.removeById(id);
//        return new ResponseResult(200, "OK", null);

//    @Resource
//    private CourseService courseService;
//    @GetMapping("/page")
//    public ResponseResult getCoursePage(
//            @RequestParam(name = "current", defaultValue = "1") int current,
//            @RequestParam(name = "pageSize", defaultValue = "10") int pageSize) {
//        PageVO page = courseService.getCoursePage(current, pageSize);
//        return new ResponseResult(200,"OK",page);
//    }
//
//    /**
//     * 新增课程
//     */
//    @PostMapping
//    public ResponseResult addCourse(@RequestBody Course course) {
//        boolean result = courseService.save(course);
//        return new ResponseResult(200,"OK",null);
//    }
//
//    /**
//     * 更新课程信息
//     */
//    @PutMapping
//    public ResponseResult updateCourse(@RequestBody Course course) {
//        boolean result = courseService.updateById(course);
//        return new ResponseResult(200,"OK",null);
//    }
//
//    /**
//     * 删除课程
//     */
//    @DeleteMapping("/{id}")
//    public ResponseResult deleteCourse(@PathVariable Integer id) {
//        boolean result = courseService.removeById(id);
//        return new ResponseResult(200,"OK",null);
//    }

//    }



    @Resource
    private CourseService courseService;
    @RequestMapping(value = "/findCourse",method = RequestMethod.GET)
    public ResponseResult findCoursePage(@RequestParam(name = "current",required = false,defaultValue = "1")int current,
                                          @RequestParam(name = "pageSize",required = false,defaultValue = "10")int pageSize){
        PageVO page = courseService.getCoursePage(current, pageSize);
        return new ResponseResult(200,"OK",page);
    }

    @RequestMapping(value = "course",method = RequestMethod.POST)
    public ResponseResult addCourse(Course course){
        courseService.save(course);
        return new ResponseResult(200,"OK",null);
    }

    @RequestMapping(value = "course",method = RequestMethod.PUT)
    public ResponseResult updateCourse(Course Course){
        courseService.updateById(Course);
        return new ResponseResult(200,"OK",null);
    }

    @RequestMapping(value = "course/{id}",method = RequestMethod.DELETE)
    public ResponseResult deleteCourse(@PathVariable Integer id){
        courseService.removeById(id);
        return new ResponseResult(200,"OK",null);
    }
}

